package service.impl;

import java.util.List;

import dao.EmployeeDao;
import entity.Department;
import entity.Employee;
import entity.PageBean;
import service.EmployeeService;

public class EmployeeServiceImpl implements EmployeeService {

	//注入dao
	private EmployeeDao employeeDao;
	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}
	public EmployeeDao getEmployeeDao() {
		return employeeDao;
	}
	public Employee login(Employee employee) {
		return employeeDao.login(employee);
	}

	public List<Employee> queryAll() {
		return employeeDao.queryAll();
	}
	public PageBean<Employee> findByPage(int currPage) {
		PageBean<Employee> pageBean = new PageBean<Employee>();
		pageBean.setCurrPage(currPage);
		int pageSize = 3;
		pageBean.setPageSize(pageSize);// 每页显示的记录数
		int totalCount = employeeDao.calCount();
		pageBean.setTotalCount(totalCount);
		double tc = totalCount;
		Double totalPage = Math.ceil(tc / pageSize);
		pageBean.setTotalPage(totalPage.intValue());
		int begin = (currPage - 1) * pageSize;
		List<Employee> list = employeeDao.findByPage(begin, pageSize);
		pageBean.setList(list);
	
		return pageBean;
	}
	public void save(Employee employee) {
		employeeDao.save(employee);
	}
	public Employee findById(Integer eid) {
		return employeeDao.findById(eid);
	}
	public void delete(Employee employee) {
		employeeDao.delete(employee);
	}
	public void update(Employee employee) {
		employeeDao.update(employee);
	}

}
